﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml.Serialization;
using Tilver.Coder.Utility;

namespace Tilver.Coder.Core
{
    /// <summary>
    /// 数据对象
    /// </summary>
    [Serializable]
    public class CoderDataObject : CoderObjectBase
    {
        /// <summary>
        /// 内部使用代码
        /// </summary>
        //public string CodeName { get; set; }
        /// <summary>
        /// 数据类型
        /// </summary>
        public DbType DbType { get; set; }
        /// <summary>
        /// C#代码
        /// </summary>
        public string CSharpType { get; set; }
        /// <summary>
        /// 数据库中的数据类型
        /// </summary>
        public string NativeType { get; set; }
        /// <summary>
        /// 是否值类型
        /// </summary>
        public bool IsValueType { get { return DBTypeUtil.IsValueType(this.DbType); } }
        /// <summary>
        /// 是否枚举类型
        /// </summary>
        public bool IsEnumType { get; set; }
        /// <summary>
        /// 是否允许生成枚举代码
        /// </summary>
        public bool AllowGenerateEnum { get; set; }
        /// <summary>
        /// 是否允许空值
        /// </summary>
        public bool AllowDBNull { get; set; }
        /// <summary>
        /// 最大位数
        /// </summary>
        public byte Precision { get; set; }
        /// <summary>
        /// 小数位数
        /// </summary>
        public int Scale { get; set; }
        /// <summary>
        /// 大小
        /// </summary>
        public int Size { get; set; }
        /// <summary>
        /// 默认值
        /// </summary>
        public string DefaultValue { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public ObjectStateEnum State { get; set; }
        /// <summary>
        /// 数据对象类型
        /// </summary>
        public virtual DataObjectTypeEnum DataType { get; set; }
        /// <summary>
        /// 构造
        /// </summary>
        public CoderDataObject()
        {
            Name = string.Empty;
            DbType = DbType.Int32;
            Size = 4;
            Description = string.Empty;
            CSharpType = DBTypeUtil.ConvertToCSharpType(DbType, AllowDBNull);
        }
    }
}
